﻿using KalevaAalto.DataPart.Excel.Base;
using KalevaAalto.DataPart.Models;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KalevaAalto.DataPart.Excel.Epplus
{
    internal class EpplusColumns : BaseColumns
    {
        private int _startColumn;
        private int _endColumn;
        private ExcelWorksheet _worksheet;
        private ExcelRangeColumn _columns => _worksheet.Columns[_startColumn, _endColumn];
        public EpplusColumns(BaseWorksheet worksheet, ExcelRangeColumn columns) : base(worksheet)
        {
            _startColumn = columns.StartColumn;
            _endColumn = columns.EndColumn;
            _worksheet = columns.Range.Worksheet;
        }

        public override BaseColumns this[int index] => new EpplusColumns(Worksheet, _worksheet.Columns[_startColumn+index-1]);
        public override int Count => _endColumn - _startColumn + 1;
        public override IStyle Sytle => new EpplusStyle(_columns.Style);
        public override double Width { set => _columns.Width = value; get => _columns.Width; }

        public override IEnumerator<BaseColumns> GetEnumerator()=> _columns.Select(it => new EpplusColumns(Worksheet, it)).GetEnumerator();


        public override void AutoFit()
        {
            _columns.AutoFit();
        }

    }
}
